using UnityEngine;

public class PlayAudioOnTrigger : MonoBehaviour
{
    [Tooltip("要播放的音效源")]
    public AudioSource audioSource;

    [Tooltip("是否只播放一次")]
    public bool playOnce = true;

    private bool hasPlayed = false;
    public GameObject game;

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            if (playOnce && hasPlayed) return;

            if (audioSource != null && !audioSource.isPlaying)
            {
                audioSource.Play();
                hasPlayed = true;
                //game.SetActive(true);
            }
        }
    }
}
